//获取应用实例
var app = getApp()
var network = require("../../utils/network.js")
Page({
    data: {
        //轮播图数据开始
        indicatorDots: true,
        vertical: false,
        autoplay: false,
        interval: 6000,
        duration: 1000, 
        nextUrl:["../homeClean/main/index"]
    },
    //l轮播图事件处理函数
    swiperchange: function(e) {
    },
    //跳转至保洁页面
    toHomeClean:function(e){
      var index = e.currentTarget.dataset.id
      var array = this.data.nextUrl
      var url = array[index]
      // var openid = wx.getStorageSync("openid")
      // var data = {}
      // data.openid = openid
      // data.phone=""
      // data.smsCode=""
      if (url){
        // network.postData(
        //   "https://api.hsb1234.com/userc/v1/login",
        //   data,
        //   function (res) {
            // 如果返回statusCode == 200跳转至保洁页面
            wx.navigateTo({
              url: url,
            })
          // },
          // function () {
            //如果返回statusCode==401跳转至登录页面
            // wx.navigateTo({
            //   url: '../public/login/index',
            // })
        //   }
        // )
      }
    } ,  
    onLoad: function() {        
      var that = this
      // var openid = wx.getStorageSync("openid")
      var data = {}
      // data.openid = openid
      network.getData(
        "https://api.hsb1234.com/userc/v1/indexPage/banners",
        data,
        function(res){
          var resdata = res.data.data
          that.setData({
            images:resdata        
          })
        }, 
        function (res) {
          wx.navigateTo({
            url: '../public/login/index',
          })
        }
      )
      var data2 = {}
      // data2.openid = openid
      data2.offset = ""
      data2.limit = ""
      network.getData(
        "https://api.hsb1234.com/userc/v1/index/service/category",
        data2,
        function(res){
          var resdata = res.data.data
          that.setData({
            server: res.data.data
          })
        },
        function(){
          wx.navigateTo({
            url: '../public/login/index',
          })
        }
      )
     
      app.getUserInfo(function(userInfo) {
        that.setData({
          userInfo: userInfo
        })       
      })
      // 把小程序分享给好友
      wx.showShareMenu({
        withShareTicket: true,
        success: function (res) {
          // 分享成功
          // console.log('shareMenu share success')         
        },
        fail: function (res) {
          // 分享失败
        }
      })
    },
     //把小程序分享给好友
    onShareAppMessage:function(){
      return  {
        title:"活速帮提供优质家政服务，让您畅享舒适生活",
        desc:"",
        path: "/pages/index/index",
        imageUrl: "http://housecleanimags-1255598775.file.myqcloud.com/screen/swiper3.jpg",
        success:function(res){
          // console.log(res.shareTickets[0])
          wx.getShareInfo({
            shareTicket: res.shareTickets[0],
            success: function (res) { 
              // console.log(res)
              },
            // fail: function (res) { console.log(res) },
          })
          wx.showToast({
            title: '成功',
            icon: 'success',
            duration: 500
          })
        },
        fail:function(){
          wx.showToast({
            title: '谢谢体验',
            icon: 'fail',
            duration: 500
          })
        }
      }
    },
})
